using System;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.DC;
using DevExpress.Data.Filtering;
using DevExpress.Persistent.Base;
using System.Collections.Generic;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.ExpressApp.SystemModule;

namespace DomainComponents.XCRM
{
    public enum InvoiceStatus
    {
        None = 0,
        Canceled = 1,
        Completed = 2,
        Partial = 3
    }

    [DomainComponent]
    [ImageName("BO_Sale")]
    [VisibleInReports]
    [Appearance("Disable Paid Invoice", TargetItems = "*", Criteria = "[Status] = 'Completed'", Enabled = false)]
    [ListViewAutoFilterRowAttribute(true)]
    [XafDisplayName("Invoice")]
    public interface IInvoice : ISaleBase
    {
        InvoiceStatus Status { get; set; }

        [VisibleInListView(false)]
        DateTime DueDate { get; set; }

        [Action(PredefinedCategory.View, Caption = "Close Invoice...", AutoCommit = true,
            TargetObjectsCriteria = "Status = 'None'",
            SelectionDependencyType = MethodActionSelectionDependencyType.RequireSingleObject)]
        void Close(CloseInvoice convertParams);

        [System.ComponentModel.Browsable(false)]
        [VisibleInListView(false)]
        ICustomer BackRefCustomer { get; set; } //TODO: duplicated with IInvoce, IOpportunity, IOrder, IQuote
    }


    [DomainLogic(typeof(IInvoice))]
    public class InvoiceLogic
    {
        public static void AfterChange_BackRefCustomer(IInvoice saleBase)
        {
            saleBase.PotentialCustomer = saleBase.BackRefCustomer;
        }
        public static void AfterChange_PotentialCustomer(IInvoice saleBase)
        {
            saleBase.BackRefCustomer = saleBase.PotentialCustomer;
        }
    }

    //[DefaultClassOptions]
    ////[ImageName("BO_Contact")]
    ////[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
    ////[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
    ////[Persistent("DatabaseTableName")]
    //// Specify more UI options using a declarative approach (http://documentation.devexpress.com/#Xaf/CustomDocument2701).
    //public class IInvoice : BaseObject
    //{ // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (http://documentation.devexpress.com/#Xaf/CustomDocument3146).
    //    public IInvoice(Session session)
    //        : base(session)
    //    {
    //    }
    //    public override void AfterConstruction()
    //    {
    //        base.AfterConstruction();
    //        // Place your initialization code here (http://documentation.devexpress.com/#Xaf/CustomDocument2834).
    //    }
    //    //private string _PersistentProperty;
    //    //[XafDisplayName("My display name"), ToolTip("My hint message")]
    //    //[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)]
    //    //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
    //    //public string PersistentProperty {
    //    //    get { return _PersistentProperty; }
    //    //    set { SetPropertyValue("PersistentProperty", ref _PersistentProperty, value); }
    //    //}

    //    //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)]
    //    //public void ActionMethod() {
    //    //    // Trigger a custom business logic for the current record in the UI (http://documentation.devexpress.com/#Xaf/CustomDocument2619).
    //    //    this.PersistentProperty = "Paid";
    //    //}
    //}
}
